package com.google.gwt.gwtpages.client.page;

import com.google.gwt.gwtpages.client.page.loader.GWTPagesLoader;

/**
 * Entity class used to contain a {@link GWTPagesPresenter} and associated data.
 * 
 * @author Joe Hudson
 */
public class GWTPage {

	private String pageToken;
	private GWTPagesPresenter presenter;
	private GWTPageAttributes attributes;
	private GWTPagesLoader pageLoader;

	/**
	 * Default constructor
	 */
	public GWTPage() {
	}

	/**
	 * Default constructor
	 */
	public GWTPage(GWTPagesPresenter presenter) {
		this.presenter = presenter;
	}

	/**
	 * @param pageToken
	 *            the specific segment of the history token which identifies the
	 *            page
	 * @param page
	 *            the loaded {@link GWTPagesPresenter}
	 * @param attributes
	 *            the {@link GWTPageAttributes} provided by the {@link GWTPagesLoader}
	 * @param pageLoader
	 *            the {@link GWTPagesLoader} used to actually load the page (useful
	 *            with nested page loaders)
	 */
	public GWTPage(String pageToken, GWTPagesPresenter presenter, GWTPageAttributes attributes,
			GWTPagesLoader pageLoader) {
		this.pageToken = pageToken;
		this.presenter = presenter;
		this.attributes = attributes;
		this.pageLoader = pageLoader;
	}

	/**
	 * Return the the specific segment of the history token which identifies the
	 * page
	 */
	public String getPageToken() {
		return pageToken;
	}

	/**
	 * Set the specific segment of the history token which identifies the page
	 * 
	 * @param pageToken
	 *            the page token
	 */
	public void setPageToken(String pageToken) {
		this.pageToken = pageToken;
	}

	/**
	 * Return the {@link GWTPagesPresenter}
	 */
	public GWTPagesPresenter getPresenter() {
		return presenter;
	}

	/**
	 * Set the {@link GWTPagesPresenter}
	 */
	public void setPage(GWTPagesPresenter presenter) {
		this.presenter = presenter;
	}

	/**
	 * Return the {@link GWTPageAttributes}
	 */
	public GWTPageAttributes getAttributes() {
		return attributes;
	}

	/**
	 * Set the {@link GWTPageAttributes}
	 */
	public void setAttributes(GWTPageAttributes attributes) {
		this.attributes = attributes;
	}

	/**
	 * Return the {@link GWTPagesLoader}
	 */
	public GWTPagesLoader getPageLoader() {
		return pageLoader;
	}

	/**
	 * Set the {@link GWTPagesLoader}
	 */
	public void setPageLoader(GWTPagesLoader pageLoader) {
		this.pageLoader = pageLoader;
	}

	/**
	 * Return a duplicate copy of this page load result
	 */
	public GWTPage copy() {
		return new GWTPage(pageToken, presenter, (null != attributes)?attributes.copy():null, pageLoader);
	}
}